Namespace OliverHine.Weather.Common

    Public Class Enums
        Public Enum Unit
            Fahrenheit
            Celsius
        End Enum

        Public Enum Style
            Today
            Extended
            OnlyExtended
            OnlyToday
            TodayWithExtended
        End Enum

        Public Enum Title
            Hide
            Closest
            Actual
        End Enum

        Public Enum HyperLinkMode
            Postback
            QueryString
            Ajax
        End Enum
    End Class

    Public Class Functions
        Private Const QueryDelimiter As Char = "O"c

        Private Shared Function BuildNewURL(ByVal PathAndQuery As String, ByVal NewQuery As String) As String
            Return BuildNewURL(PathAndQuery) & NewQuery
        End Function

        Private Shared Function BuildNewURL(ByVal PathAndQuery As String) As String
            If PathAndQuery.IndexOf("?") = -1 Then
                BuildNewURL = PathAndQuery & "?"
            Else
                If PathAndQuery.EndsWith("?") Then
                    BuildNewURL = PathAndQuery 'PathAndQuery.Substring(0, PathAndQuery.Length - 1)
                Else
                    If PathAndQuery.EndsWith("&") = False Then
                        BuildNewURL = PathAndQuery & "&"
                    Else
                        BuildNewURL = PathAndQuery
                    End If
                End If
            End If
        End Function

        Public Shared Function BuildQuerystringUrl(ByVal Request As System.Web.HttpRequest, ByVal UniqueIdentifier As String) As String

            Dim queryKey As String = "weather"
            Dim newQueryString As String = "weather={0}"
            If Not Request.QueryString(queryKey) Is Nothing Then
                'query key exists

                Dim queryValue As String = Request.QueryString(queryKey)
                If queryValue.IndexOf(QueryDelimiter) = -1 Then
                    'query value doesn't contain the delimiter

                    If UniqueIdentifier = queryValue Then
                        BuildQuerystringUrl = BuildNewURL(Request.Url.PathAndQuery.Replace(String.Format(newQueryString, UniqueIdentifier), String.Empty))
                    Else
                        BuildQuerystringUrl = BuildNewURL(Request.Url.PathAndQuery.Replace(String.Format(newQueryString, queryValue), String.Empty), String.Format(newQueryString, queryValue & QueryDelimiter & UniqueIdentifier))
                    End If
                Else
                    'query value DOES contain the delimiter

                    Dim queryParams As Array = queryValue.Trim.Split(QueryDelimiter)
                    Dim newQueryValue As String = String.Empty
                    For Each s As String In queryParams
                        If s.Length > 0 Then
                            If UniqueIdentifier = s Then
                                newQueryValue = queryValue.Replace(s, String.Empty)
                                Exit For
                            Else
                                newQueryValue = queryValue & QueryDelimiter & UniqueIdentifier
                            End If
                        End If

                    Next
                    Dim doubleDelimiter As String = QueryDelimiter & QueryDelimiter
                    newQueryValue = newQueryValue.Trim(QueryDelimiter).Replace(doubleDelimiter, QueryDelimiter)

                    BuildQuerystringUrl = BuildNewURL(Request.Url.PathAndQuery.Replace(String.Format(newQueryString, queryValue), String.Empty), String.Format(newQueryString, newQueryValue))
                End If
            Else
                BuildQuerystringUrl = BuildNewURL(Request.Url.PathAndQuery, String.Format(newQueryString, UniqueIdentifier))
            End If

        End Function


        Private Shared Function BuildRequestURL(ByVal sLocationToBind As String, ByVal iLengthToDisplay As Integer, ByVal DisplayUnit As Common.Enums.Unit) As String
            'http://xoap.weather.com/weather/local/13210?cc=*&dayf={1}&prod=xoap&par=1092534366&key=77a84c2ba0a26bc5
            Dim reqUrl As New System.Text.StringBuilder("http://xoap.weather.com/weather/local/")
            reqUrl.Append(String.Format("{0}?prod=xoap&cc=y&dayf={1}", sLocationToBind, iLengthToDisplay + 1))

            If Not Configuration.ConfigurationSettings.AppSettings.Item("Weather.PartnerId") Is Nothing And Not Configuration.ConfigurationSettings.AppSettings.Item("Weather.LicenseKey") Is Nothing Then
                reqUrl.Append(String.Format("&par={0}&key={1}", Configuration.ConfigurationSettings.AppSettings.Item("Weather.PartnerId").ToString(), Configuration.ConfigurationSettings.AppSettings.Item("Weather.LicenseKey").ToString()))
            Else
                reqUrl.Append(String.Format("&par={0}&key={1}", "1092534366", "77a84c2ba0a26bc5"))
            End If

            ' if the unit is Celsius then append the unit querystring to the Request URL
            If DisplayUnit = Enums.Unit.Celsius Then reqUrl.Append("&unit=m")
            ''System.Web.HttpContext.Current.Response.Write(reqUrl.ToString)
            Return reqUrl.ToString
        End Function

        Public Shared Function SearchForLocation(ByVal Location As String) As DataSet
            Dim reqUrl As String = String.Format("http://xoap.weather.com/search/search?where={0}", Location)
            Dim WebRequest As New Controls.Helpers.Web.MakeRequest
            Dim wr As Net.HttpWebRequest = WebRequest.Create(reqUrl)
            If Not wr Is Nothing Then
                'load the response into a response object

                Dim resp As System.Net.WebResponse = wr.GetResponse()
                ' create a new stream that can be placed into an XmlTextReader
                Dim str As System.IO.Stream = resp.GetResponseStream()
                Dim reader As System.Xml.XmlTextReader = New System.Xml.XmlTextReader(str)

                Dim ds As New DataSet
                ds.ReadXml(reader, XmlReadMode.Auto)

                reader.Close()
                str.Close()
                resp.Close()
                Return ds
            End If
        End Function

        Public Shared Function GetWeatherDocument(ByVal sLocationToBind As String, ByVal iLengthToDisplay As Integer, ByVal DisplayUnit As Common.Enums.Unit, ByVal Language As String, ByVal ProxyServer As String, ByVal ProxyPort As Integer, ByVal ProxyUsername As String, ByVal ProxyPassword As String) As Xml.XmlDocument
            Dim cacheKey As String = String.Format("w:{0}:{1}:{2}:{3}", sLocationToBind, iLengthToDisplay, DisplayUnit, System.Globalization.CultureInfo.CurrentUICulture.Name)
            If System.Web.HttpContext.Current.Cache.Item(cacheKey) Is Nothing Then
                'cache doesn't exist yet, so lets create it

                Dim objWebRequest As New Controls.Helpers.Web.MakeRequest

                Dim wr As System.Net.HttpWebRequest = objWebRequest.Create(BuildRequestURL(sLocationToBind, iLengthToDisplay, DisplayUnit), ProxyServer, ProxyPort, ProxyUsername, ProxyPassword)

                If Not wr Is Nothing Then
                    'load the response into a response object
                    Dim resp As System.Net.WebResponse = wr.GetResponse()
                    ' create a new stream that can be placed into an XmlTextReader
                    Dim str As IO.Stream = resp.GetResponseStream()

                    Dim reader As Xml.XmlTextReader = New Xml.XmlTextReader(str)
                    reader.XmlResolver = Nothing

                    ' create a new Xml document
                    GetWeatherDocument = New Xml.XmlDocument
                    GetWeatherDocument.Load(reader)

                    ' close the various objects we don't need any longer
                    reader.Close()
                    str.Close()
                    resp.Close()

                    Dim xErrorNode As Xml.XmlNode = GetWeatherDocument.SelectSingleNode("error")
                    If Not xErrorNode Is Nothing Then
                        'litScripts.Text = xErrorNode.Item("err").InnerText()
                    Else
                        'Translate the XML before caching it
                        TranslateXML(GetWeatherDocument, Language)
                    End If

                    System.Web.HttpContext.Current.Cache.Add(cacheKey, GetWeatherDocument, Nothing, Now.AddMinutes(30), TimeSpan.Zero, Web.Caching.CacheItemPriority.AboveNormal, Nothing)

                End If
            Else
                GetWeatherDocument = DirectCast(System.Web.HttpContext.Current.Cache.Item(cacheKey), Xml.XmlDocument)
            End If

            '' System.Web.HttpContext.Current.Response.Write("<textarea>" & GetWeatherDocument.OuterXml & "</textarea>")

        End Function
#Region " current conditions"
        Private Shared Sub TranslateXML(ByRef xDocument As Xml.XmlDocument, ByVal Language As String)
            Dim xErrorNode As Xml.XmlNode = xDocument.SelectSingleNode("error")
            If Not xErrorNode Is Nothing Then
                'litScripts.Text = xErrorNode.Item("err").InnerText()
                xDocument = Nothing
            Else
                'current conditions replacement
                Dim xNode As Xml.XmlNode = xDocument.SelectSingleNode("weather//cc")
                'Dim xNewNode As Xml.XmlNode = xNode

                If Not xNode.Item("lsup") Is Nothing Then
                    Dim time As String = xNode.Item("lsup").InnerText
                    Dim DateSyntax As String = "M/d/yy"
                    If time.StartsWith(Now.ToString(DateSyntax)) Then
                        xNode.Item("lsup").InnerText = time.Replace(Now.ToString(DateSyntax) & " ", String.Empty)
                    ElseIf time.StartsWith(Now.AddDays(-1).ToString(DateSyntax)) Then
                        xNode.Item("lsup").InnerText = time.Replace(Now.AddDays(-1).ToString(DateSyntax) & " ", String.Empty)
                    Else
                        xNode.Item("lsup").InnerText = Now.ToString(DateSyntax) & " " & time
                    End If
                End If

                TranslateConditionsText(xNode, Language)
                TranslateBarText(xNode, Language)
                TranslateVisibiltyText(xNode, Language)
                TranslateConditionsWind(xNode, Language)
                TranslateConditionsUV(xNode, Language)

                'xDocument.DocumentElement.ReplaceChild(xNewNode, xNode)

                Dim xNodeList As Xml.XmlNodeList = xDocument.SelectNodes("weather//dayf")

                xNode = xDocument.SelectSingleNode("weather//dayf")


                If xNode.HasChildNodes = True Then
                    'starts the dayf loop
                    For i As Integer = 0 To xNode.ChildNodes.Count - 1
                        If xNode.ChildNodes(i).Name = "day" Then

                            TranslateWeekDayText(xNode.ChildNodes(i), Language)

                            If xNode.ChildNodes(i).HasChildNodes = True Then
                                For ii As Integer = 0 To xNode.ChildNodes(i).ChildNodes.Count - 1
                                    If xNode.ChildNodes(i).ChildNodes(ii).Name = "part" Then

                                        TranslateConditionsText(xNode.ChildNodes(i).ChildNodes(ii), Language)

                                    End If
                                Next
                            End If

                        End If
                    Next
                End If
            End If

        End Sub

        Private Shared Sub TranslateWeekDayText(ByRef xNewNode As Xml.XmlNode, ByVal Language As String)
            'If xNewNode.Attributes("t") Then
            Select Case xNewNode.Attributes("t").InnerText.ToLower()
                Case "sunday"
                    xNewNode.Attributes("t").InnerText = Controls.Helpers.Localization.GetString("xml.Day.Sunday", Language)
                Case "monday"
                    xNewNode.Attributes("t").InnerText = Controls.Helpers.Localization.GetString("xml.Day.Monday", Language)
                Case "tuesday"
                    xNewNode.Attributes("t").InnerText = Controls.Helpers.Localization.GetString("xml.Day.Tuesday", Language)
                Case "wednesday"
                    xNewNode.Attributes("t").InnerText = Controls.Helpers.Localization.GetString("xml.Day.Wednesday", Language)
                Case "thursday"
                    xNewNode.Attributes("t").InnerText = Controls.Helpers.Localization.GetString("xml.Day.Thursday", Language)
                Case "friday"
                    xNewNode.Attributes("t").InnerText = Controls.Helpers.Localization.GetString("xml.Day.Friday", Language)
                Case "saturday"
                    xNewNode.Attributes("t").InnerText = Controls.Helpers.Localization.GetString("xml.Day.Saturday", Language)
            End Select
            'End If
        End Sub

        Private Shared Sub TranslateVisibiltyText(ByRef xNewNode As Xml.XmlNode, ByVal Language As String)
            If xNewNode.Item("vis") IsNot Nothing Then
                Select Case xNewNode.Item("vis").InnerText.ToLower()
                    Case "unlimited"
                        xNewNode.Item("vis").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Visibility.Unlimited", Language)
                End Select
            End If
        End Sub

        Private Shared Sub TranslateBarText(ByRef xNewNode As Xml.XmlNode, ByVal Language As String)
            If xNewNode.Item("bar") IsNot Nothing Then
                Select Case xNewNode.Item("bar").Item("d").InnerText.ToLower()
                    Case "steady"
                        xNewNode.Item("bar").Item("d").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Bar.Steady", Language)
                    Case "rising"
                        xNewNode.Item("bar").Item("d").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Bar.Rising", Language)
                    Case "falling"
                        xNewNode.Item("bar").Item("d").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Bar.Falling", Language)
                End Select
            End If
        End Sub

        Private Shared Sub TranslateConditionsText(ByRef xNewNode As Xml.XmlNode, ByVal Language As String)


            If xNewNode.Item("icon") IsNot Nothing AndAlso Microsoft.VisualBasic.IsNumeric(xNewNode.Item("icon").InnerText) Then
                Select Case CInt(xNewNode.Item("icon").InnerText) '= Localization.GetString("xml.CurrentConditionText")
                    Case 0
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Thunderstorms", Language)
                    Case 1
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.WindyRain", Language)
                    Case 2
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.WindyRain", Language)
                    Case 3
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Thunderstorms", Language)
                    Case 4
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.HeavyThunderstorm", Language)
                    Case 5
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.SnowRainMix", Language)
                    Case 6
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Hail", Language)
                    Case 7
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.SnowRainIcyMix", Language)
                    Case 8
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.LightRainIcy", Language)
                    Case 9
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.LightRain", Language)
                    Case 10
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.HeavyRainIcy", Language)
                    Case 11
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Rain", Language)
                    Case 12
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.HeavyRain", Language)
                    Case 13
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.LightSnow", Language)
                    Case 14
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Snow", Language)
                    Case 15
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Snowflakes", Language)
                    Case 16
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.HeavySnow", Language)
                    Case 17
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Thunderstorms", Language)
                    Case 18
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Hail", Language)
                    Case 19
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Dust", Language)
                    Case 20
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Fog", Language)
                    Case 21
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Haze", Language)
                    Case 22
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Smoke", Language)
                    Case 23
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Windy", Language)
                    Case 24
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Windy", Language)
                    Case 25
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Frigid", Language)
                    Case 26
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Cloudy", Language)
                    Case 27
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.MostlyCloudyNight", Language)
                    Case 28
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.MostlyCloudyDay", Language)
                    Case 29
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.PartlyCloudyNight", Language)
                    Case 30
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.PartlyCloudyDay", Language)
                    Case 31
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.ClearNight", Language)
                    Case 32
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.SunnyDay", Language)
                    Case 33
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.FairNight", Language)
                    Case 34
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.LightPartlyCloudyDay", Language)
                    Case 35
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Thunderstorms", Language)
                    Case 36
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.HotSunnyDay", Language)
                    Case 37
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.IsolatedThunderstorms", Language)
                    Case 38
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Lightening", Language)
                    Case 39
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.HeavyRain", Language)
                    Case 40
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.HeavyRain", Language)
                    Case 41
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.HeavySnow", Language)
                    Case 42
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.HeavySnow", Language)
                    Case 43
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.WindySnowy", Language)
                    Case 44
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.PartlyCloudyDay", Language)
                    Case 45
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.RainyNight", Language)
                    Case 46
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.SnowyNight", Language)
                    Case 47
                        xNewNode.Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.ThunderstormsNight", Language)
                End Select
            End If
        End Sub

        Private Shared Sub TranslateConditionsWind(ByRef xNewNode As Xml.XmlNode, ByVal Language As String)

            If xNewNode.Item("wind") IsNot Nothing AndAlso xNewNode.Item("wind").Item("s") IsNot Nothing Then
                Select Case xNewNode.Item("wind").Item("s").InnerText.ToLower
                    Case "calm"
                        xNewNode.Item("wind").Item("s").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.Calm", Language)
                    Case "breezy"
                        xNewNode.Item("wind").Item("s").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.Breezy", Language)
                    Case "none", "n/a"
                        xNewNode.Item("wind").Item("s").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.None", Language)
                    Case "var", "variable"
                        xNewNode.Item("wind").Item("s").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.Variable", Language)
                End Select
            End If

            If xNewNode.Item("wind") IsNot Nothing AndAlso xNewNode.Item("wind").Item("gust") IsNot Nothing Then
                Select Case xNewNode.Item("wind").Item("gust").InnerText.ToLower
                    Case "light air"
                        xNewNode.Item("wind").Item("gust").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.LightAir", Language)
                    Case "slight breeze"
                        xNewNode.Item("wind").Item("gust").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.SlightBreeze", Language)
                    Case "gentle breeze"
                        xNewNode.Item("wind").Item("gust").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.GentleBreeze", Language)
                    Case "moderate breeze"
                        xNewNode.Item("wind").Item("gust").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.ModerateBreeze", Language)
                    Case "fresh breeze"
                        xNewNode.Item("wind").Item("gust").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.FreshBreeze", Language)
                    Case "strong breeze"
                        xNewNode.Item("wind").Item("gust").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.StrongBreeze", Language)
                    Case "high wind"
                        xNewNode.Item("wind").Item("gust").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.HighWind", Language)
                    Case "gale"
                        xNewNode.Item("wind").Item("gust").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.Gale", Language)
                    Case "strong gale"
                        xNewNode.Item("wind").Item("gust").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.StrongGale", Language)
                    Case "storm"
                        xNewNode.Item("wind").Item("gust").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.Storm", Language)
                    Case "violent storm"
                        xNewNode.Item("wind").Item("gust").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.ViolentStorm", Language)
                    Case "Hurricane"
                        xNewNode.Item("wind").Item("gust").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.Hurricane", Language)
                    Case "n/a", "none"
                        xNewNode.Item("wind").Item("gust").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.None", Language)
                End Select
            End If

            If xNewNode.Item("wind") IsNot Nothing AndAlso xNewNode.Item("wind").Item("t") IsNot Nothing Then
                Select Case xNewNode.Item("wind").Item("t").InnerText.ToLower
                    Case "calm"
                        xNewNode.Item("wind").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.Calm", Language)
                    Case "breezy"
                        xNewNode.Item("wind").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.Breezy", Language)

                    Case "n"
                        xNewNode.Item("wind").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.N", Language)
                    Case "s"
                        xNewNode.Item("wind").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.S", Language)
                    Case "e"
                        xNewNode.Item("wind").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.E", Language)
                    Case "w"
                        xNewNode.Item("wind").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.W", Language)
                    Case "nw"
                        xNewNode.Item("wind").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.NW", Language)
                    Case "sw"
                        xNewNode.Item("wind").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.SW", Language)
                    Case "ne"
                        xNewNode.Item("wind").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.NE", Language)
                    Case "se"
                        xNewNode.Item("wind").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.SE", Language)
                    Case "nne"
                        xNewNode.Item("wind").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.NNE", Language)
                    Case "sse"
                        xNewNode.Item("wind").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.SSE", Language)
                    Case "nnw"
                        xNewNode.Item("wind").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.NNW", Language)
                    Case "ssw"
                        xNewNode.Item("wind").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.SSW", Language)
                    Case "ene"
                        xNewNode.Item("wind").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.ENE", Language)
                    Case "ese"
                        xNewNode.Item("wind").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.ESE", Language)
                    Case "wnw"
                        xNewNode.Item("wind").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.WNW", Language)
                    Case "wsw"
                        xNewNode.Item("wind").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.WSW", Language)
                    Case "var", "variable"
                        xNewNode.Item("wind").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.Variable", Language)
                    Case "n/a", "none"
                        xNewNode.Item("wind").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.Wind.None", Language)
                End Select
            End If
        End Sub

        Private Shared Sub TranslateConditionsUV(ByRef xNewNode As Xml.XmlNode, ByVal Language As String)
            If xNewNode.Item("uv") IsNot Nothing AndAlso xNewNode.Item("uv").Item("t") IsNot Nothing Then
                Select Case xNewNode.Item("uv").Item("t").InnerText.ToLower
                    Case "none", "n/a"
                        xNewNode.Item("uv").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.UV.None", Language)
                    Case "low"
                        xNewNode.Item("uv").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.UV.Low", Language)
                    Case "moderate"
                        xNewNode.Item("uv").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.UV.Moderate", Language)
                    Case "high"
                        xNewNode.Item("uv").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.UV.High", Language)
                    Case "very high"
                        xNewNode.Item("uv").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.UV.VeryHigh", Language)
                    Case "extreme"
                        xNewNode.Item("uv").Item("t").InnerText = Controls.Helpers.Localization.GetString("xml.Conditions.UV.Extreme", Language)
                End Select
            End If
        End Sub

#End Region

    End Class

End Namespace